<template>
  <transition name="slide-left">
    <div v-if="show" class="flight-alert" role="alert">
      <div class="anomaly-item">
        <el-tag type="danger" color="">禁飞区警告</el-tag>
        <span class="anomaly-time">{{ formatTime(new Date()) }}</span>
        <p class="anomaly-desc">无人机DR-005接近禁飞区</p>
      </div>
      <button class="close" aria-label="关闭" @click="$emit('close')">×</button>
    </div>
  </transition>
</template>

<script setup>
import { ref } from "vue";
const props = defineProps({
  show: { type: Boolean, default: false },
  message: {
    type: String,
    default: "当前区域存在飞行限制，请谨慎操作。",
  },
});

// 格式化时间
const formatTime = (time) => {
  return new Date(time).toLocaleString("zh-CN");
};

defineEmits(["close"]);
</script>

<style scoped lang="scss">
.flight-alert {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 999;
  min-width: 280px;
  max-width: 420px;
  padding: 12px 36px 12px 12px;
  background-color: #171f2f;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s;
  color: #1d2129;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}
:deep(.anomaly-list) {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.anomaly-item {
  cursor: pointer;
  transition: all 0.3s;
}
.anomaly-time {
  display: block;
  font-size: 12px;
  color: #e5e7eb;
  margin-top: 4px;
}
.anomaly-desc {
  margin: 8px 0 0 0;
  font-size: 14px;
  color: #e70606;
}

.close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 22px;
  height: 22px;
  line-height: 18px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: #ecf4ff;
  cursor: pointer;
}
.close:hover {
  background: rgba(0, 0, 0, 0.06);
}

.el-tag {
  background: rgb(130, 26, 26);
  border-color: rgb(161, 4, 4);
  color: #ffffff;
}

/* 左侧滑入动画 */
.slide-left-enter-from,
.slide-left-leave-to {
  transform: translateX(-120%);
  opacity: 0;
}
.slide-left-enter-active,
.slide-left-leave-active {
  transition: all 0.35s ease;
}
.slide-left-enter-to,
.slide-left-leave-from {
  transform: translateX(0);
  opacity: 1;
}
</style>
